package com.yimixian.app.util;


import com.ta.utdid2.android.utils.StringUtils;
import com.umeng.analytics.MobclickAgent;
import com.yimixian.app.SystemFramework;
import com.yimixian.app.common.SharePreferenceKeys;
import com.yimixian.app.common.UMengConstants;
import com.yimixian.app.model.Address;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

/**
 * Created by zhilian-2 on 2016/1/27.
 */
public class DateUtil {


    private static final String RFC_1123_DATE_TIME = "EEE, dd MMM yyyy HH:mm:ss z";
    public static Date parseRfc1123DateTime(String string) {
        try {
            return new SimpleDateFormat(RFC_1123_DATE_TIME, Locale.US).parse(string);
        } catch (ParseException e) {
            return null;
        }
    }

    /**
     * 友盟统计--根据城市
     * @param hashMap
     * @param eventType
     */
    public static void setCityUMeng(Map<String, String> hashMap, String eventType){
        Address mAddress = SharedPreferencesHelper.getAddress(SharePreferenceKeys.CURRENT_ADDRESS);
        if (mAddress != null && !StringUtils.isEmpty(mAddress.city)){
            if (hashMap == null) hashMap = new HashMap<>();
            hashMap.put("city", mAddress.city);
            MobclickAgent.onEvent(SystemFramework.getInstance().getGlobalContext(),
                    eventType, hashMap);
        }else if (hashMap != null) {
            MobclickAgent.onEvent(SystemFramework.getInstance().getGlobalContext(),
                    eventType, hashMap);
        }else{
            MobclickAgent.onEvent(SystemFramework.getInstance().getGlobalContext(),
                    eventType);
        }
    }

}
